
*For Margaret dropbox folders 
global NCREIF "/Users/BeckaBrolinson/Dropbox/NCREIF/data" 
global build 	"$NCREIF/build" 
global analysis "$NCREIF/analysis"
global results 	"$analysis/results"
global figures 	"$analysis/figures" 

*Run the FE regression of real util per sqft on treat*post 
set more off 

	#d ;
	global Cov0 	""; 
	global Cov1 	"Covered_E real_elecprice real_gasprice Unemployment HDD1000s CDD1000s 
	age age2 used_space1000s
	 percentleased real_capex_ti_sqft real_capex_bldimp_sqft "; 
	global Cov2 	"Covered_E real_elecprice real_gasprice Unemployment HDD1000s CDD1000s
	 age age2 percentleased used_space1000s
	dFundType1 dFundType2 dFundType4 dFundType5 dFundType6";
	global Cov3	"Covered_E real_elecprice Unemployment HDD1000s CDD1000s 
	age age2 used_space1000s"; 
	#d cr 

	**DIFF IN DIFF 
	forvalues i=2/3{
	use "$build/FakeNCREIFAnnualizedDatawcontrol_PostMatch`i'_wmatches.dta", clear 
	
	gen sqft1000s = sqft / 1000 
	gen HDD1000s = HDD / 1000 
	gen CDD1000s = CDD / 1000 
	gen used_space1000s = used_space/ 1000
	gen real_capex_ti_sqft = real_capex_ti / sqft 
	gen real_capex_bldimp_sqft = real_capex_bldimp / sqft 
	
	gen years_pre_post_cert= year-firstyearrated
	gen post_1 = (years_pre_post_cert>=-1) 
	gen interaction_1 = post_1 * treat 

	
	*label variables for regression tables 	
	label var interaction "Cert*Post" 
	label var interaction_1 "Cert*Post (Including Year Prior to Cert.)"
	label var treat "1[treat=1]"
	label var logrealrentpersf "ln(Rent/Sq. Ft.) (\\$)"
	label var Covered_E "Benchmarking Law" 
	label var real_elecprice "Avg. Elec. Price (\\$/MWh)" 
	label var real_gasprice "Avg. Gas Price (\\$/Mcf)" 
	label var Unemployment "Unemployment" 
	label var age "Building Age" 
	label var age2 "Building Age Squared" 
	label var used_space "Used Space (Pct. Leased * Sq. Ft.)"
	label var used_space1000s "Used Space (Pct. Leased * Sq. Ft.) (1000s)"
	labe var percentleased "Percent Leased (\%)"
	label var real_capex_ti "Cap Exp. (Tenant Imp.)" 
	label var real_capex_ti_sqft "Cap Exp./Sq. Ft. (Tenant Imp.) (\\$)"
	label var real_capex_bldimp "Cap Exp. (Bldg. Imp.)"
	label var real_capex_bldimp_sqft "Cap Exp./Sq. Ft. (Bldg. Imp.) (\\$)"
	label var HDD "HDD" 
	label var HDD1000s "HDD (1000s)" 
	label var CDD "CDD" 
	label var CDD1000s "CDD (1000s)" 
	label var rl_yr_rentpersf "Rent per Sq. Ft."
	label var logrealutilpersf "ln(Util/Sq. Ft.) (\\$)"
	label var rl_yr_rentpersf "Rent per Sq. Ft."
	label var rl_yr_utilpersf "Util. per Sq. Ft."
	label var yrbuilt "Year Built" 
	label var sqft "Square Feet"
	label var sqft1000s "Square Feet (1000s)" 
	
	
	*Run the FE regression of real rent per sqft on treat*post 
	local Covariates "Cov0 Cov1 Cov2 Cov3" 
	foreach Cov of local Covariates{
	eststo RentFE1_1: reghdfe logrealrentpersf interaction_1 i.treat, absorb(i.city_cat#i.year) vce(cluster cbsa)
	estfe  RentFE1_1, labels(year "Year FE" city_cat#year "City by Year FE")
	eststo RentCov1_FE_1: reghdfe logrealrentpersf interaction_1 i.treat $Cov1, absorb(i.city_cat#i.year) vce(cluster cbsa)
	estfe  RentCov1_FE_1, labels(year "Year FE" city_cat#year "City by Year FE")
	eststo RentFE`Cov'_1: reghdfe logrealrentpersf interaction_1 $`Cov', absorb(i.propnum i.city_cat#i.year) vce(cluster cbsa)
	estfe  RentFE`Cov'_1, labels(year "Year FE" city_cat#year "City by Year FE" propnum "Property FE")
	}
	
		
	*make Latex Table 
	esttab RentFE1_1 RentCov1_FE_1 RentFECov1_1 RentFECov3_1 using "$results/04_01_rentpersf_matched`i'.tex" , label replace booktabs ///
	alignment(SSSS) ///
	b(%12.3f) se(%12.3f) star(* 0.05) /// sets format of parameters, standard errors, and stars
	stats(N, fmt(%9.0fc)) /// adds comma to Observation number
	nonotes nogaps /// removes notes from bottom of table 
	indicate(`r(indicate_fe)', label("Y" "")) /// adds y & N for FE inclusions
	title(Matched Sample: Energy Star Certification and Rent Per Sq. Ft. \label{appendixtab0401rentpersfmatched`i'}) ///
	addnote({\scriptsize * p$<$0.05. The standard errors reported in parenthesis have been clustered at the CBSA level.})

*using hdfe
	local Covariates "Cov0 Cov1 Cov2 Cov3" 
	foreach Cov of local Covariates{
	eststo UtilFE1_1: reghdfe logrealutilpersf interaction_1 i.treat, absorb(i.city_cat#i.year) vce(cluster cbsa)
	estfe  UtilFE1_1, labels(year "Year FE" city_cat#year "City by Year FE")
	eststo UtilCov1_FE_1: reghdfe logrealutilpersf interaction_1 i.treat $Cov1 , absorb(i.city_cat#i.year) vce(cluster cbsa)
	estfe  UtilCov1_FE_1, labels(year "Year FE" city_cat#year "City by Year FE")
	eststo UtilFE`Cov'_1: reghdfe logrealutilpersf interaction_1 rl_yr_rentpersf $`Cov' , absorb(i.propnum i.city_cat#i.year) vce(cluster cbsa)
	estfe  UtilFE`Cov'_1, labels(year "Year FE" city_cat#year "City by Year FE" propnum "Property FE")
	}
	
			
	*make Latex Table 
	esttab UtilFE1_1 UtilCov1_FE_1 UtilFECov1_1 UtilFECov3_1 using "$results/05_01_utilpersf_matched`i'.tex" , label replace booktabs ///
	alignment(SSSS) ///
	b(%12.3f) se(%12.3f) star(* 0.05) /// sets format of parameters, standard errors, and stars
	stats(N, fmt(%9.0fc)) /// adds comma to Observation number
	nonotes nogaps /// removes notes from bottom of table 
	indicate(`r(indicate_fe)', label("Y" "")) /// adds y & N for FE inclusions
	title(Matched Sample: Energy Star Certification and Utility Expenditure Per Sq. Ft. \label{appendixtab0501utilpersfmatched`i'}) ///
	addnote({\scriptsize * p$<$0.05. The standard errors reported in parenthesis have been clustered at the CBSA level.})
	

	} 
	
